<template>
  <el-dialog
    :title="dialogTitle"
    :visible.sync="roomShow"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    width="990px"
    center>
    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="80px">
      <div class="user-title">客户信息</div>
      <div class="user-info">
        <el-form-item label="联系人：" size="mini" prop="ContactName">
          <el-autocomplete
            v-model="ruleForm.ContactName"
            :fetch-suggestions="querySearchAsync"
            placeholder="请输入内容"
            @select="val=>{ruleForm.ContactPhone=val.Phone}"
          ></el-autocomplete>
        </el-form-item>
        <el-form-item label="手机号：" size="mini" prop="ContactPhone">
          <el-input :maxlength="11" v-model="ruleForm.ContactPhone"></el-input>
        </el-form-item>
        <el-form-item label="来源渠道：" size="mini" label-width="95px" prop="FromChannel">
          <el-select v-model="ruleForm.FromChannel" placeholder="请选择" @change="getFromChannel1(ruleForm.FromChannel)">
            <el-option
              v-for="m in ChannelList"
              :label="m.Name"
              :value="parseInt(m.Code)"
              :key="m.Code">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="渠道商：" size="mini" label-width="80px" prop="TravelAgency" v-if="!!ChannelChildList.length">
          <el-select v-model="ruleForm.TravelAgency" placeholder="请选择" filterable>
            <el-option
              v-for="m in ChannelChildList"
              :label="m.Name"
              :value="parseInt(m.Code)"
              :key="m.Code">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="销售员：" size="mini" label-width="80px" prop="SalesmanId">
            <el-select v-model="ruleForm.SalesmanId" placeholder="请选择" filterable clearable>
              <el-option
                v-for="m in SalesmanList"
                :label="m.Name"
                :value="m.Id"
                :key="m.Id">
              </el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="支付类型：" size="mini" label-width="95px" prop="PaymentMode">
            <el-select v-model="ruleForm.PaymentMode" placeholder="请选择">
              <el-option :label="'全额预付'" :value="1"></el-option>
              <el-option :label="'部分预付'" :value="2"></el-option>
              <el-option :label="'到店现付'" :value="3"></el-option>
              <el-option :label="'已担保（未支付）'" :value="4"></el-option>
            </el-select>
        </el-form-item>
      </div>
      <div class="user-title">
        房间信息 <span class="el-icon-circle-plus-outline"
        @click="dialogData.push({PolicyId:dialogData[0].PolicyId,AllAmount:0,PolicyPriceAmount:0,endDate:dialogData[dialogData.length-1].endDate,startDate:dialogData[dialogData.length-1].startDate,roomNum:'',roomId:'',Roomers:[]})">
        添加房间</span>
      </div>
      <div class="room-form">
        <div class="room-row" v-for="(m,index) in dialogData">
          <el-form-item label="房间：" label-width="60px" prop="RoomCategoryId">
            <el-select v-model="m.RoomCategoryId" size="mini" placeholder="请选择" @change="val=>{getMroomData(m,val)}">
              <el-option
                v-for="n in roomNumData"
                :key="n.roomId"
                :label="n.RoomCategoryName"
                :value="n.roomId">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="房号：" label-width="60px" size="mini" prop="roomNum">
            <el-select v-model="m.roomNum" placeholder="请选择" @change="val=>{getRoomId(m,val)}">
              <el-option
                :label="'未排房'"
                :value="0">
              </el-option>
              <el-option
                v-for="n in m.roomData"
                :key="n.RoomId"
                :label="n.RoomName"
                :value="n.RoomName">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="到达" size="mini" label-width="50px" prop="startDate" class="date-form sdate">
            <el-date-picker
              v-model="m.startDate"
              type="datetime"
              placeholder="到达时间"
              value-format="yyyy-MM-dd HH:mm:ss"
              align="right"
              :learable="false"
              :editable="false"
              :clearable="false"
              :picker-options="startOptions"
               @change="getendDate(m,index)"
              >
            </el-date-picker>
          </el-form-item>
          <el-form-item label="离开" size="mini" label-width="50px" prop="endDate" class="date-form edate">
            <el-date-picker
              v-model="m.endDate"
              type="datetime"
              placeholder="离开时间"
              value-format="yyyy-MM-dd HH:mm:ss"
              align="right"
              :learable="false"
              :editable="false"
              :clearable="false"
              :picker-options="endOptions"
               @change="getMroomPrcie(m)">
            </el-date-picker>
          </el-form-item>
          <div>
             <span class="el-icon-remove-outline" v-if="dialogData.length>1&&m.Status!==1" @click="deleteRoomPro('dialogData',index)">删除房间</span>
          </div>
          <div class="user-in">
             <span style="margin-bottom:15px;" class="el-icon-circle-plus-outline"  @click="m.Roomers.push({Name:'',CertType:'',CertNo:''})">添加入住人</span>
             <el-form-item label="房费：" style="margin-left: 450px;" label-width="60px" size="mini" prop="AllAmount">
               <el-input v-model="m.AllAmount" @change="getAllAmount"></el-input>
             </el-form-item>
             <div v-for="(n,nindex) in m.Roomers">
               <el-form-item label="入住人姓名：" label-width="100px" size="mini" prop="Name">
                 <el-input v-model="n.Name"></el-input>
               </el-form-item>
               <el-form-item label="证件类型：" label-width="100px" size="mini" prop="CertType">
                 <el-select class="s-select" v-model="n.CertType" placeholder="请选择" @change="n.CertNo=''">
                   <el-option label="身份证" :value="1"></el-option>
                   <el-option label="护照" :value="2"></el-option>
                   <el-option label="军官证" :value="3"></el-option>
                   <el-option label="通行证" :value="4"></el-option>
                   <el-option label="其他" :value="5"></el-option>
                 </el-select>
               </el-form-item>
               <el-form-item label="入住人证件号：" label-width="110px" size="mini" prop="CertNo">
                 <el-input v-model="n.CertNo">
                 </el-input>
               </el-form-item>
               <span class="el-icon-remove-outline" @click="m.Roomers.splice(nindex,1)">删除</span>
             </div>
          </div>
        </div>
      </div>
      <div class="user-title">消费信息 <span class="el-icon-circle-plus-outline"
        @click="ProductList.push({ProductType:'',ProductId:'',UnitPrice:'',Quantity:'',AllAmount:'',Unit:'',SellingPriceAmount:0,ProductNameList:[]})">添加商品</span></div>
      <div class="price-form">
        <div class="room-row" v-for="(m,index) in ProductList">
          <el-form-item label="类别：" label-width="60px" size="mini" prop="ProductType">
            <el-select v-model="m.ProductType" placeholder="请选择" @change="GetSingleProductByType(m)">
              <el-option label="休闲娱乐" :value="6701"></el-option>
              <el-option label="房间消费" :value="6702"></el-option>
              <el-option label="土特产" :value="6703"></el-option>
              <el-option label="旅游交通" :value="6704"></el-option>
              <el-option label="餐饮" :value="6705"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="名称：" label-width="60px" size="mini" prop="ProductId">
            <el-select v-model="m.ProductId" placeholder="请选择" @change="getUnitPrice(m)">
              <el-option
                v-for="n in m.ProductNameList"
                :key="n.Id"
                :label="n.Name"
                :value="n.Id">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="单价：" label-width="60px" size="mini" prop="UnitPrice">
            <el-input v-model="m.UnitPrice" type="number" @change="getUnitPrice(m)"></el-input>
          </el-form-item>
          <el-form-item label="数量：" label-width="60px" size="mini" prop="Quantity" class="num-input">
            <el-input-number v-model="m.Quantity" :min="1" @change="getUnitPrice(m)" label="数量"></el-input-number>
          </el-form-item>
          <el-form-item label="小计：" label-width="60px" size="mini" prop="AllAmount">
            <el-input v-model="m.AllAmount" @change="getAllAmount"></el-input>
          </el-form-item>
          <div>
             <span class="el-icon-remove-outline" @click="deleteRoomPro('ProductList',index)">删除商品</span>
          </div>
        </div>
      </div>
      <template v-if="dialogTitle==='预定'||dialogTitle==='直接入住'||dialogTitle==='补录'">
      <div style="padding-right:20px;margin: 10px;">
        <el-dropdown trigger="hover" placement="top" @command="addPriceInfo">
          <span class="el-dropdown-link" style="cursor:pointer;color: #399be6;margin-left:10px;">添加款项</span>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item :command="{type:1,name:'收款'}">收款</el-dropdown-item>
            <el-dropdown-item :command="{type:2,name:'商品'}">商品</el-dropdown-item>
            <el-dropdown-item :command="{type:3,name:'收押金'}">收押金</el-dropdown-item>
            <el-dropdown-item :command="{type:4,name:'退款'}">退款</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </div>
      <el-table
        :data="tableData"
        style="width: 95%;margin:5px auto 15px;max-height: 200px;overflow: auto;"
        v-show="true">
        <el-table-column
          prop="CashierItem"
          label="项目">
          <template slot-scope="scope">
            {{CashierItem[scope.row.CashierItem]}}
          </template>
        </el-table-column>
        </el-table-column>
        <el-table-column
          prop="Amount"
          label="收款">
        </el-table-column>
        <el-table-column
          label="支付方式">
          <template slot-scope="scope">
            {{getCash(scope.row.CashierChannel)}}
          </template>
        </el-table-column>
        <el-table-column
          prop="Remark"
          label="财务备注">
          <template slot-scope="scope">
            {{scope.row.Remark||''}}
          </template>
        </el-table-column>
        <el-table-column
          label="操作"
          class="delete-td">
          <template slot-scope="scope">
            <span @click="tableData.splice(scope.index,1)" style="color:rgb(57, 155, 230);cursor:pointer;">删除</span>
          </template>
        </el-table-column>
      </el-table>
      </template>
      <div class="user-title remark-div">
        <el-form-item label="备注：" label-width="60px" prop="Remark">
          <el-input type="textarea" v-model="ruleForm.Remark"></el-input>
        </el-form-item>
      </div>
      <div class="price-div">
        <span>订单总金额：{{ruleForm.AllAmount}} 元</span>
        <span>销售总金额：{{ruleForm.SellingPriceAmount}}元</span>
      </div>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitOrder">{{OrderAction===2?'直接入住':OrderAction===0?'确认修改':'预定'}}</el-button>
      <el-button @click="roomShow = false">取 消</el-button>
    </span>
  </el-dialog>
</template>
<script>
  export default {
    props:['formData','title'],
    data() {
      return {
        showInfo:false,
        timeList:[],
        orderInfoData:{},
      }
    },
    created() {
    },
    methods: {
      notice(){
        this.timeList=[];
        this.orderSerialid=id;
        this.$ajax.getorderdetail({OrderSerialid:this.orderSerialid}).then(res=>{
          if(res.Success){
            this.orderInfoData=res.Data;
            this.orderInfo=true;
            this.tableShow=false;
            if(this.roomoutShow||this.roominShow){

            }else{
              this.roomoutShow=false;
              this.roominShow=false;
            }
          }
        })
      },
      editOrder(){
        this.dialogData=[];
        this.ruleForm={};
        this.ProductList=[];
        this.ruleForm=_.cloneDeep(this.orderInfoData);
        this.ruleForm.RoomList=this.ruleForm.HotelOrders;
        this.ProductList=this.ruleForm.SingleProductOrders;
        _.map(this.ruleForm.RoomList,val=>{
          this.dialogData.push({
            roomName:val.RoomCategoryName,
            "PolicyName": val.RoomCategoryName,
            "PolicyId": val.RoomCategoryPolicyId,
            "HotelId": JSON.parse(sessionStorage.getItem('nowmenu')).Id,
            "HotelName": JSON.parse(sessionStorage.getItem('nowmenu')).name,
            "roomId": val.RoomCategoryId,
            "Id":val.RoomId,
            "HotelOrderId":val.Id,
            "roomNum": val.RoomNo,
            "startDate": val.CheckInDate,
            "endDate": val.CheckOutDate,
            "Days": this.getAlldate(val.CheckInDate,val.CheckOutDate).length-1,
            "AllAmount": val.AllAmount,
            "PolicyPriceAmount": val.PolicyPriceAmount,
            Status:val.Status,
            "Roomers": val.Roomers
          })
        })
        delete this.ruleForm.HotelOrders;
        delete this.ruleForm.SingleProductOrders;
        this.dialogTitle='修改订单';
        this.OrderAction=0;
        _.map(this.ProductList,(val,index)=>{
          this.$ajax.GetSingleProductByType({type:val.ProductType,hotelId:JSON.parse(sessionStorage.getItem('nowmenu')).Id}).then(res=>{
            if(res.Success){
              this.$set(this.ProductList[index],'ProductNameList',res.Data)
            }
          })
        })
        this.getAllAmount();
        _.map(this.dialogData,(val,index)=>{
          let data={
            HotelOrderId:val.HotelOrderId||0,
            CheckInTime:val.startDate,
            CheckOutTime:val.endDate,
            RoomCategoryId:val.roomId,
            HotelId:val.HotelId
          }
          val.roomData=[];
          this.$ajax.GetAvailableRooms(data).then(res=>{
            if(res.Success){
              val.roomData=res.Data;
              this.$set(this.dialogData,index,val)
            }
          })
          return val;
        })
        this.$nextTick(()=>{
          this.showAddRoom();
        })
      },
      toggleDiolag(){
        this.showInfo=!this.showInfo;
        if(this.showInfo){
          this.notice();
        }
      }
    }
  }

</script>
<style lang="scss">
.clearfix:after{content:".";display:block;height:0;clear:both;visibility:hidden}
.info-dialog .el-dialog__body{
  padding:0 20px;
}
.time-main{
  overflow: hidden;
}
.time-left{
  width: 15%;
  text-align: right;
  margin-top: 20px;
  padding-right: 20px;
  box-sizing: border-box;
  z-index: 2;
}
.time-first:before{
  content: '';
  height: 15px;
  position: absolute;
  right:-1px;
  background: #fff;
  width: 1px;
}
.time-left,.time-right{
  float: left;
  position: relative;
  line-height: 40px;
}
.time-right{
  width: 80%;
  padding: 0 20px;
  margin-top: 20px;
  &:before{
    content: '';
    height: 150%;
    position: absolute;
    left: 0px;
    background: #409eff;
    width: 1px;
  }
  z-index: 1;
  box-shadow: 3px 3px 3px 0px #409eff5e;
  p:first-child{
    color:#000;
    span{
      float: right;
    }
  }
}
.title-day{
  overflow: hidden;
  color: #ef7c29;
  font-size: 16px;
  font-weight: bold;
}
.title-day .time-left:after{
  border: solid transparent;
  content: ' ';
  height: 20px;
  right: -12px;
  top:9px;
  position: absolute;
  width: 20px;
  border-radius: 20px;
  background: #fff;
  border: 2px solid #ef7c29;
}
.title-time .time-left:after{
  content: ' ';
  height: 10px;
  right: -6px;
  top: 14px;
  position: absolute;
  width: 10px;
  border-radius: 10px;
  background: #ef7c29;
  border: 1px solid #ef7c29;
}
.title-time .bg-blue.time-left:after{
  background: #409EFF;
  border: 1px solid #409EFF;
}
.title-end{
  width: 15%;
  left:1px;
  text-align: right;
  border-right:1px solid #409EFF;
  padding-right: 20px;
  margin-right: 20px;
  box-sizing: border-box;
  height: 30px;
  position: relative;
}

.title-end:after, .title-end:before {
  border: solid transparent;
  content: ' ';
  height: 0;
  right: -11px;
  position: absolute;
  width: 0;
}
.title-end:after {
  border-width: 10px;
  border-top-color: #409EFF;
  top: 20px;
}
</style>
